package com.ftwj.demo.generate.utils;

import java.io.File;
import java.io.IOException;
import java.util.Locale;

import freemarker.template.Configuration;

/**
*
* <p>Title: FreemarkerConfigUtil</p>  
* <p>Description: Freemak环境变量初始化</p>
* <p>Copyright: Copyright (c) 2020 </p>  
* <p>Company: 兰州飞天网景信息产业有限公司</p>    
* @author WangSLi
* @date 2020年2月27日 下午11:50:27
* @version V1.0
 */
public class FreemarkerConfigUtil {
	
	private static String path=FreemarkerConfigUtil.class.getResource("/ftl").getPath();
	
	private static Configuration configuration;
	
	public static synchronized Configuration getInstance() throws IOException {
		if(configuration==null) {
			configuration=new Configuration(Configuration.getVersion());
            if (path.contains("jar")){
                configuration.setClassForTemplateLoading(FreemarkerConfigUtil.class, "/ftl");
            } else {
                configuration.setDirectoryForTemplateLoading(new File(path));
            }
			configuration.setEncoding(Locale.CHINA, "utf-8");
			configuration.setClassicCompatible(true);
		}
		return configuration;
	}

}
